﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TimeTracker.XmlProvider
{
    public class XNoteElement : INote
    {
        public XElement BaseElement
        {
            get;
            private set;
        }
        
        public XNoteElement(XElement other)
        {
            this.BaseElement = other;
        }

        public XNoteElement()
        {
            this.BaseElement = new XElement("note");
        }

        ISession INote.Session
        {
            get {
                XElement element = this.BaseElement.Parent.Parent;

                if (element.Name == "session")
                {
                    return new XSessionElement(element);
                }
                
                return null;
            }
        }

        string INote.Text
        {
            get
            {
                return this.BaseElement.Value;
            }
            set
            {
                this.BaseElement.SetValue(value);
            }
        }

        DateTime INote.Time
        {
            get
            {
                return Convert.ToDateTime(this.BaseElement.Attribute("time").Value);
            }
            set
            {
                this.BaseElement.SetAttributeValue("time", value);
            }
        }
    }
}
